package com.zxt.smartplatform.controller;

import com.zxt.smartplatform.dto.R;
import com.zxt.smartplatform.pojo.Scene;
import com.zxt.smartplatform.pojo.User;
import com.zxt.smartplatform.service.SceneService;
import com.zxt.smartplatform.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/scenes")
public class SceneController {


    private SceneService sceneService;

    @Autowired
    public void setSceneService(SceneService sceneService) {
        this.sceneService = sceneService;
    }


    @PostMapping("/scene")
    public R addScene(@RequestBody Scene scene) {
        sceneService.addScene(scene);
        return R.setOK();
    }

    @GetMapping("/scenes")
    public R findAllSceneByUser() {
        User user = SecurityUtils.getUser();
        List<Scene> sceneList = sceneService.findByUserId(user.getUId());
        return R.setOK(sceneList);
    }

}
